//
//  XMGCollectionViewCell.m
//  小码哥彩票
//
//  Created by 徐悟源 on 16/3/8.
//  Copyright (c) 2016年 xiaomage. All rights reserved.
//

#import "XMGCollectionViewCell.h"
#import "XMGTabBarController.h"

@interface XMGCollectionViewCell()

@property (nonatomic , weak) UIImageView *imageView;

@property (nonatomic , weak) UIButton *startButton;

@end

@implementation XMGCollectionViewCell

- (UIButton *)startButton
{
    if(_startButton == nil)
    {
        //UIButton *startButton =
        
        _startButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_startButton setBackgroundImage:[UIImage imageNamed:@"guideStart"] forState:UIControlStateNormal];
        
        [_startButton sizeToFit];
        
        [_startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
        
        _startButton.center = CGPointMake(self.width * 0.5, self.height * 0.9);
        
        [self.contentView addSubview:_startButton];
    }
    
    return _startButton;
}

- (void)setUpIndexPath:(NSIndexPath *)indexPath count:(NSInteger)pagesCount
{
    if(indexPath.row == pagesCount - 1)
    {
        self.startButton.hidden = NO;
        
    }
    else
    {
        self.startButton.hidden = YES;
    }

}

- (UIImageView *)imageView
{
    if(_imageView == nil)
    {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:self.bounds];
        
        _imageView = imageV;
        
        [self.contentView addSubview:imageV];
    }
    return _imageView;
}

- (void)setImage:(UIImage *)image
{
    _image = image;
    self.imageView.image = image;
}


- (void)start
{
    [UIApplication sharedApplication].keyWindow.rootViewController = [[XMGTabBarController alloc]init];
    
    CATransition *anim = [CATransition animation];
    anim.duration = 0.5;
    anim.type = @"RippleEffect";
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
}

@end
